package com.game.majiang.algorithm.niuniu;

import java.util.Arrays;
import java.util.Vector;


public class cardlogic {

	/**
	 * 客服端发过来 的牌 和 服务器的牌是否一致
	 * */
	private static boolean isallhave(Vector<card> cards, Vector<card> mycards)
	{
		boolean ishaves = true;//是不是牌都存在
		for(int i=0; i<cards.size(); i++)
		{
			boolean ishave = false;//是不是这张牌存在
			for(int j=0; j<mycards.size(); j++)
			{
				if(cards.get(i).type.get_value() == mycards.get(j).type.get_value())
				{
					ishave = true;
				}
			}
			if(!ishave)
			{
				ishaves = false;
				break;
			}
		}
		return ishaves;
	}
	/**
	 * 牌的点数
	 * */
	private static int checkniu(Vector<card> niu, Vector<card> point)//3张 2张
	{
		int recpoint = 0;//点数
		int allpoint = 0;
		for(int i=0; i<niu.size(); i++)
		{
			allpoint += niu.get(i).type.getpoint();
		}
		if(allpoint%10 == 0)
		{
			//加起来是10的倍数 有牛
			for(int i=0; i<point.size(); i++)
			{
				recpoint += point.get(i).type.getpoint();
			}
			recpoint = recpoint%10;
			if(recpoint == 0)
			{
				recpoint = 10;//有牛的时候point 0是牛10
			}
		}
		return recpoint;
	}
	private static boolean tonghuashun(Vector<card> cards)//5张
	{
		boolean flag = true;
		int type = cards.get(0).type.get_type();
		for(int i=0; i<cards.size(); i++)
		{
			if(type != cards.get(i).type.get_type())
			{
				return false;
			}
		}
		if(!shunzi(cards))
		{
			return false;
		}
		return flag;
	}

	private static boolean tonghua(Vector<card> cards)//5张
	{
		boolean flag = true;
		int type = cards.get(0).type.get_type();
		for(int i=0; i<cards.size(); i++)
		{
			if(type != cards.get(i).type.get_type())
			{
				return false;
			}
		}
		return flag;
	}

	private static int findpointcount(int val, Vector<card> cards)
	{
		int point = 0;
		if(val <=40)
		{
			point = val%10;
			if(point == 0)
			{
				point = 10;
			}
		}
		else if(val >= 51 && val<=83)
		{
			point = val%10 + 10;
		}
		else
		{
			return 1;
		}
		int count = 0;
		for(int i=0; i<cards.size(); i++)
		{
			int temppoint = 0;
			int tempval = cards.get(i).type.get_value();
			if(tempval <=40)
			{
				temppoint = tempval%10;
				if(temppoint == 0)
				{
					temppoint = 10;
				}
			}
			else if(tempval >= 51 && tempval<=83)
			{
				temppoint = tempval%10 + 10;
			}
			else
			{
				temppoint = 0;
			}
			if(point == temppoint)
			{
				count++;
			}
		}
		return count;
	}
	private static int zhadan(Vector<card> cards, Vector<card> zucards)//5张
	{
		int flag = 0;
		for(int i=0; i<cards.size(); i++)
		{
			if(findpointcount(cards.get(i).type.get_value(), cards) == 4)
			{
				flag = cards.get(i).type.get_value();

				if(flag <=40)
				{
					flag = flag%10;
					if(flag == 0)
					{
						flag = 10;
					}
				}
				else if(flag >= 51 && flag<=83)
				{
					flag = flag%10 + 10;
				}
				break;
			}
		}
		zucards.clear();
		for(int i=0; i<cards.size(); i++)
		{
			int flag2 = cards.get(i).type.get_value();
			if(flag2 <=40)
			{
				flag2 = flag2%10;
				if(flag2 == 0)
				{
					flag2 = 10;
				}
			}
			else if(flag2 >= 51 && flag2<=83)
			{
				flag2 = flag2%10 + 10;
			}
			if(flag == flag2)
			{
				zucards.add(new card(cards.get(i).type.get_value()));
			}
		}
		for(int i=0; i<cards.size(); i++)
		{
			int flag2 = cards.get(i).type.get_value();
			if(flag2 <=40)
			{
				flag2 = flag2%10;
				if(flag2 == 0)
				{
					flag2 = 10;
				}
			}
			else if(flag2 >= 51 && flag2<=83)
			{
				flag2 = flag2%10 + 10;
			}
			if(flag != flag2)
			{
				zucards.add(new card(cards.get(i).type.get_value()));
			}
		}
		return flag;
	}
	private static boolean quandan(Vector<card> cards)//5张
	{
		boolean flag = true;
		for(int i=0; i<cards.size(); i++)
		{
			if(cards.get(i).type.get_value()%2 == 0)
			{
				flag = false;
			}
		}
		return flag;
	}
	private static int hulu(Vector<card> cards)//5张
	{
		int flag = 0;
		int max3 = 0;
		int max2 = 0;
		for(int i=0; i<cards.size(); i++)
		{
			if(findpointcount(cards.get(i).type.get_value(), cards) == 3)
			{
				max3 = cards.get(i).type.get_value();
			}
			else if(findpointcount(cards.get(i).type.get_value(), cards) == 2)
			{
				max2 = cards.get(i).type.get_value();
			}
		}
		if(max3 != 0 && max2 != 0)
		{
			flag = max3;

			if(flag <=40)
			{
				flag = flag%10;
				if(flag == 0)
				{
					flag = 10;
				}
			}
			else if(flag >= 51 && flag<=83)
			{
				flag = flag%10 + 10;
			}
		}
		return flag;
	}
	public static boolean shunzi(Vector<card> cards)//5张
	{
		boolean flag = true;
		int min = 100;
		int arr[] = new int[5];
		for(int i=0; i<cards.size(); i++)
		{
			int po = cards.get(i).type.get_value();
			if(po <=40)
			{
				po = po%10;
				if(po == 0)
				{
					po = 10;
				}
			}
			else if(po >= 51 && po<=83)
			{
				po = po%10 + 10;
			}
			if(po < min)
			{
				min = po;
			}
			arr[i] = po;
		}
		Arrays.sort(arr);
		for(int i=0; i<arr.length; i++)
		{
			if(min != arr[i])
			{
				//点数对不上 考虑10 j q k A的情况
				if(min == 2 )
				{
					if(min+(14-cards.size()-1) !=arr[i] )
					{
						//最小是a 1   加上9 不等于10(下一张牌) 
						return false;
					}else{
						min = arr[i];
					}
				}
				else
				{
					return false;
				}
			}
				min+=1;
	
		}
		return flag;
	}
	/**
	 * 是否是五小牛
	 * */
	private static boolean checkwuxiaoniu(Vector<card> cards)//5张
	{
		boolean flag = false;
		int allpoint = 0;
		for(int i=0; i<cards.size(); i++)
		{
			allpoint += cards.get(i).type.getpoint();
		}
		if(allpoint <= 10)
		{
			flag = true;
		}
		return flag;
	}
	/**
	 * 是否是五大牛
	 * */
	private static boolean checkwudaniu(Vector<card> cards)//5张
	{
		boolean flag = false;
		int allpoint = 0;
		for(int i=0; i<cards.size(); i++)
		{
			allpoint += cards.get(i).type.getpoint();
		}
		if(allpoint >= 40)
		{
			flag = true;
		}
		return flag;
	}
	/**
	 * 是否是五花牛
	 * */
	private static boolean checkwuhuaniu(Vector<card> cards)//5张
	{
		boolean flag = true;
		for(int i=0; i<cards.size(); i++)
		{
			if(cards.get(i).type.get_value() < 41)
			{
				flag = false;
			}
		}
		return flag;
	}
	/**
	 * 3张牌 是否能组牛
	 * */
	private static boolean ishaveniu(int p1, int p2, int p3)
	{
		if((p1+p2+p3)%10 == 0)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	/**
	 * 获取手牌 所有3张牌组合 有牛的组合 
	 * */
	private static Vector<Vector<card>> splitcards(Vector<card> mycards)
	{
		Vector<Vector<card>> rec = new Vector<Vector<card>>();
		for(int i=0; i<mycards.size(); i++)
		{
			for(int j=i+1; j<mycards.size(); j++)
			{
				for(int k=j+1; k<mycards.size(); k++)
				{
					if(ishaveniu(mycards.get(i).type.getpoint(), mycards.get(j).type.getpoint(), mycards.get(k).type.getpoint()))
					{
						Vector<card> temp = new Vector<card>();
						temp.addElement(mycards.get(i));
						temp.addElement(mycards.get(j));
						temp.addElement(mycards.get(k));
						rec.addElement(temp);
					}
				}
			}
		}
		return rec;
	}
	/**
	 * 获得 自己手牌 除了组成牛的三张牌 剩下的两张牌
	 * */
	private static Vector<card> othercard(Vector<card> niu, Vector<card> mycards)
	{
		Vector<card> rec = new Vector<card>();
		for(int i=0; i<mycards.size(); i++)
		{
			boolean you = false;
			for(int j=0; j<niu.size(); j++)
			{
				if(mycards.get(i).type.get_value() == niu.get(j).type.get_value())
				{
					you=true;
					break;
				}
			}

			if(!you){
				rec.addElement(mycards.get(i));
			}
		}
		return rec;
	}
	/**
	 * 玩家手牌 能组成最大的牌型
	 * 
	 * */
	private static int findmax(Vector<Vector<card>> cardvecs, Vector<card> mycards, Vector<card> zucards, Vector<card> points)
	{
		Vector<card> tempvec = new Vector<card>();
		int curniupoint = 0;
		for(int i=0; i<cardvecs.size(); i++)
		{
			Vector<card> niu = cardvecs.get(i);
			Vector<card> point = othercard(niu, mycards);
			int niupoint = checkniu(niu, point);
			if(niupoint > curniupoint)
			{
				curniupoint = niupoint;
				if(!tempvec.isEmpty())
				{
					tempvec.clear();
				}
				if(!points.isEmpty())
				{
					points.clear();
				}
				if(!zucards.isEmpty())
				{
					zucards.clear();
				}
				for(int j=0; j<niu.size(); j++)
				{
					tempvec.addElement(niu.get(j));
					points.addElement(niu.get(j));
					zucards.add(niu.get(j));
				}
				for(int j=0; j<point.size(); j++)
				{
					tempvec.addElement(point.get(j));
					zucards.add(point.get(j));
				}
			}
		}
		mycards.clear();
		for(int i=0; i<tempvec.size(); i++)
		{
			mycards.addElement(tempvec.get(i));
		}
		Vector<card> dianshucard1 = new Vector<card>();
		Vector<card> dianshucard2 = new Vector<card>();
		Vector<card> dianshucard3 = new Vector<card>();
		Vector<card> dianshucard4 = new Vector<card>();
		Vector<card> dianshucard5 = new Vector<card>();
		int dianshuc1 = 0;
		int dianshuc2 = 0;
		int dianshuc3 = 0;
		boolean fl = true;
		dianshuc1 = finpoint(1, points, dianshucard1);
		dianshuc2 = finpoint(8, points, dianshucard2);
		if(dianshuc1 == 2 && dianshuc2 == 1 && fl)
		{
			dianshucard4.add(dianshucard1.get(0));
			dianshucard4.add(dianshucard1.get(1));
			dianshucard4.add(dianshucard2.get(0));
			fl = false;
		}
		dianshuc1 = 0;
		dianshuc2 = 0;
		dianshuc3 = 0;
		dianshuc1 = finpoint(1, points, dianshucard1);
		dianshuc2 = finpoint(2, points, dianshucard2);
		dianshuc3 = finpoint(7, points, dianshucard3);
		if(dianshuc1 == 1 && dianshuc2 == 1 && dianshuc3 == 1 && fl)
		{
			dianshucard4.add(dianshucard1.get(0));
			dianshucard4.add(dianshucard2.get(0));
			dianshucard4.add(dianshucard3.get(0));
			fl = false;
		}
		dianshuc1 = 0;
		dianshuc2 = 0;
		dianshuc3 = 0;
		dianshuc1 = finpoint(1, points, dianshucard1);
		dianshuc2 = finpoint(3, points, dianshucard2);
		dianshuc3 = finpoint(6, points, dianshucard3);
		if(dianshuc1 == 1 && dianshuc2 == 1 && dianshuc3 == 1 && fl)
		{
			dianshucard4.add(dianshucard1.get(0));
			dianshucard4.add(dianshucard2.get(0));
			dianshucard4.add(dianshucard3.get(0));
			fl = false;
		}
		dianshuc1 = 0;
		dianshuc2 = 0;
		dianshuc3 = 0;
		dianshuc1 = finpoint(1, points, dianshucard1);
		dianshuc2 = finpoint(4, points, dianshucard2);
		dianshuc3 = finpoint(5, points, dianshucard3);
		if(dianshuc1 == 1 && dianshuc2 == 1 && dianshuc3 == 1 && fl)
		{
			dianshucard4.add(dianshucard1.get(0));
			dianshucard4.add(dianshucard2.get(0));
			dianshucard4.add(dianshucard3.get(0));
			fl = false;
		}
		dianshuc1 = 0;
		dianshuc2 = 0;
		dianshuc3 = 0;
		dianshuc1 = finpoint(2, points, dianshucard1);
		dianshuc2 = finpoint(6, points, dianshucard2);
		if(dianshuc1 == 2 && dianshuc2 == 1 && fl)
		{
			dianshucard4.add(dianshucard1.get(0));
			dianshucard4.add(dianshucard1.get(1));
			dianshucard4.add(dianshucard2.get(0));
			fl = false;
		}
		dianshuc1 = 0;
		dianshuc2 = 0;
		dianshuc3 = 0;
		dianshuc1 = finpoint(2, points, dianshucard1);
		dianshuc2 = finpoint(3, points, dianshucard2);
		dianshuc3 = finpoint(5, points, dianshucard3);
		if(dianshuc1 == 1 && dianshuc2 == 1 && dianshuc3 == 1 && fl)
		{
			dianshucard4.add(dianshucard1.get(0));
			dianshucard4.add(dianshucard2.get(0));
			dianshucard4.add(dianshucard3.get(0));
			fl = false;
		}
		dianshuc1 = 0;
		dianshuc2 = 0;
		dianshuc3 = 0;
		dianshuc1 = finpoint(3, points, dianshucard1);
		dianshuc2 = finpoint(4, points, dianshucard2);
		if(dianshuc1 == 2 && dianshuc2 == 1 && fl)
		{
			dianshucard4.add(dianshucard1.get(0));
			dianshucard4.add(dianshucard1.get(1));
			dianshucard4.add(dianshucard2.get(0));
			fl = false;
		}
		dianshuc1 = 0;
		dianshuc2 = 0;
		dianshuc3 = 0;
		dianshuc1 = finpoint(4, points, dianshucard1);
		dianshuc2 = finpoint(2, points, dianshucard2);
		if(dianshuc1 == 2 && dianshuc2 == 1 && fl)
		{
			dianshucard4.add(dianshucard1.get(0));
			dianshucard4.add(dianshucard1.get(1));
			dianshucard4.add(dianshucard2.get(0));
			fl =false;
		}
		dianshuc1 = 0;
		dianshuc2 = 0;
		dianshuc3 = 0;
		dianshuc1 = finpoint(4, points, dianshucard1);
		dianshuc2 = finpoint(7, points, dianshucard2);
		dianshuc3 = finpoint(9, points, dianshucard3);
		if(dianshuc1 == 1 && dianshuc2 == 1 && dianshuc3 == 1 && fl)
		{
			dianshucard4.add(dianshucard1.get(0));
			dianshucard4.add(dianshucard2.get(0));
			dianshucard4.add(dianshucard3.get(0));
			fl =false;
		}
		dianshuc1 = 0;
		dianshuc2 = 0;
		dianshuc3 = 0;
		dianshuc1 = finpoint(5, points, dianshucard1);
		dianshuc2 = finpoint(6, points, dianshucard2);
		dianshuc3 = finpoint(9, points, dianshucard3);
		if(dianshuc1 == 1 && dianshuc2 == 1 && dianshuc3 == 1 && fl)
		{
			dianshucard4.add(dianshucard1.get(0));
			dianshucard4.add(dianshucard2.get(0));
			dianshucard4.add(dianshucard3.get(0));
			fl = false;
		}
		dianshuc1 = 0;
		dianshuc2 = 0;
		dianshuc3 = 0;
		dianshuc1 = finpoint(5, points, dianshucard1);
		dianshuc2 = finpoint(7, points, dianshucard2);
		dianshuc3 = finpoint(8, points, dianshucard3);
		if(dianshuc1 == 1 && dianshuc2 == 1 && dianshuc3 == 1 && fl)
		{
			dianshucard4.add(dianshucard1.get(0));
			dianshucard4.add(dianshucard2.get(0));
			dianshucard4.add(dianshucard3.get(0));
			fl =false;
		}
		dianshuc1 = 0;
		dianshuc2 = 0;
		dianshuc3 = 0;
		dianshuc1 = finpoint(6, points, dianshucard1);
		dianshuc2 = finpoint(8, points, dianshucard2);
		if(dianshuc1 == 2 && dianshuc2 == 1 && fl)
		{
			dianshucard4.add(dianshucard1.get(0));
			dianshucard4.add(dianshucard1.get(1));
			dianshucard4.add(dianshucard2.get(0));
			fl =false;
		}
		dianshuc1 = 0;
		dianshuc2 = 0;
		dianshuc3 = 0;
		dianshuc1 = finpoint(7, points, dianshucard1);
		dianshuc2 = finpoint(6, points, dianshucard2);
		if(dianshuc1 == 2 && dianshuc2 == 1 && fl)
		{
			dianshucard4.add(dianshucard1.get(0));
			dianshucard4.add(dianshucard1.get(1));
			dianshucard4.add(dianshucard2.get(0));
			fl = false;
		}
		dianshuc1 = 0;
		dianshuc2 = 0;
		dianshuc3 = 0;
		dianshuc1 = finpoint(8, points, dianshucard1);
		dianshuc2 = finpoint(4, points, dianshucard2);
		if(dianshuc1 == 2 && dianshuc2 == 1 && fl)
		{
			dianshucard4.add(dianshucard1.get(0));
			dianshucard4.add(dianshucard1.get(1));
			dianshucard4.add(dianshucard2.get(0));
			fl =false;
		}
		dianshuc1 = 0;
		dianshuc2 = 0;
		dianshuc3 = 0;
		dianshuc1 = finpoint(9, points, dianshucard1);
		dianshuc2 = finpoint(2, points, dianshucard2);
		if(dianshuc1 == 2 && dianshuc2 == 1 && fl)
		{
			dianshucard4.add(dianshucard1.get(0));
			dianshucard4.add(dianshucard1.get(1));
			dianshucard4.add(dianshucard2.get(0));
			fl =false;
		}
		dianshuc1 = 0;
		dianshuc2 = 0;
		dianshuc3 = 0;
		dianshuc1 = finpoint(3, points, dianshucard1);
		dianshuc2 = finpoint(8, points, dianshucard2);
		dianshuc3 = finpoint(9, points, dianshucard3);
		if(dianshuc1 == 1 && dianshuc2 == 1 && dianshuc3 == 1 && fl)
		{
			dianshucard4.add(dianshucard1.get(0));
			dianshucard4.add(dianshucard2.get(0));
			dianshucard4.add(dianshucard3.get(0));
			fl =false;
		}
		if(zucards.size() == 4)
		{
			dianshucard5.add(zucards.get(3));
		}
		else if(zucards.size() == 5)
		{
			if(zucards.get(3).getType().getdianshu() > zucards.get(4).getType().getdianshu())
			{
				dianshucard5.add(zucards.get(4));
				dianshucard5.add(zucards.get(3));
			}
			else
			{
				dianshucard5.add(zucards.get(3));
				dianshucard5.add(zucards.get(4));
			}
		}
		if(dianshucard4.size() >= 3)
		{
			zucards.clear();
			zucards.add(dianshucard4.get(0));
			zucards.add(dianshucard4.get(1));
			zucards.add(dianshucard4.get(2));
			if(dianshucard5.size() == 1)
			{
				zucards.add(dianshucard5.get(0));
			}
			else if(dianshucard5.size() == 2)
			{
				zucards.add(dianshucard5.get(0));
				zucards.add(dianshucard5.get(1));
			}
		}
		return curniupoint;
	}
	public static int finpoint(int dianshu, Vector<card> mycard, Vector<card> dianshucard)
	{
		dianshucard.clear();
		int count = 0;
		for(int i=0; i<mycard.size(); i++)
		{
			if(mycard.get(i).type.getdianshu() == dianshu)
			{
				dianshucard.add(mycard.get(i));
				count++;
			}
		}
		return count;
	}
	/**
	 * 庄家 和 闲家 牌型相同  比较 双方最大的一张牌
	 * 
	 * */
	public static boolean checkwin(Vector<card> cards1, Vector<card> cards2)
	{
		boolean flag = true;
		int curmax = 0;
		for(int i=0; i<cards1.size(); i++)
		{
			if(curmax < cards1.get(i).type.get_strong())
			{
				curmax = cards1.get(i).type.get_strong();
			}
		}
		for(int i=0; i<cards2.size(); i++)
		{
			if(curmax < cards2.get(i).type.get_strong())
			{
				flag = false;
				break;
			}
		}
		return flag;
	}
	/**
	 * 什么牌型
	 * @param wuhuaniu 
	 * @param zhadanniu 
	 * @param wuxiaoniu 
	 * code 0 普通   1 特殊  2疯狂
	 * */
	public static niutyperec checkniutypetimeover(Vector<card> mycards, Vector<card> zucards, int code)
	{
		niutyperec rec = new niutyperec();
		if(mycards.size() < 5)
		{
			return rec;
		}
		rec.ran = 0;
		int zhadan = zhadan(mycards, zucards);
//		int hulu = hulu(mycards);

//		if(checkwuxiaoniu(mycards)&&code>0)
//		{
//			rec.rec = 0;
//			rec.type2 = niutype.wuxiaoniu;
//		}
//		else 
		if(checkwudaniu(mycards)&&code>0)
		{
			rec.rec = 0;
			rec.type2 = niutype.wudaniu;
		}
		else if(zhadan>0&&code>0)
		{
			rec.rec = 0;switch (zhadan) {
			case 1:		
				rec.type2 = niutype.zhadana;		
				break;
			case 2:				
				rec.type2 = niutype.zhadan2;
				break;
			case 3:			
				rec.type2 = niutype.zhadan3;	
				break;
			case 4:			
				rec.type2 = niutype.zhadan4;	
				break;
			case 5:			
				rec.type2 = niutype.zhadan5;	
				break;
			case 6:			
				rec.type2 = niutype.zhadan6;	
				break;
			case 7:			
				rec.type2 = niutype.zhadan7;	
				break;
			case 8:			
				rec.type2 = niutype.zhadan8;	
				break;
			case 9:			
				rec.type2 = niutype.zhadan9;	
				break;
			case 10:		
				rec.type2 = niutype.zhadan10;		
				break;
			case 11:		
				rec.type2 = niutype.zhadanj;		
				break;
			case 12:		
				rec.type2 = niutype.zhadanq;		
				break;
			case 13:		
				rec.type2 = niutype.zhadank;		
				break;
			}
		}
//		else if(hulu>0&&code>0)
//		{
//			rec.rec = 0;switch (hulu) {
//			case 1:		
//				rec.type = niutype.hulua;		
//				break;
//			case 2:				
//				rec.type = niutype.hulu2;
//				break;
//			case 3:			
//				rec.type = niutype.hulu3;
//				break;
//			case 4:			
//				rec.type = niutype.hulu4;
//				break;
//			case 5:			
//				rec.type = niutype.hulu5;
//				break;
//			case 6:			
//				rec.type = niutype.hulu6;
//				break;
//			case 7:			
//				rec.type = niutype.hulu7;
//				break;
//			case 8:			
//				rec.type = niutype.hulu8;
//				break;
//			case 9:			
//				rec.type = niutype.hulu9;	
//				break;
//			case 10:		
//				rec.type = niutype.hulu10;		
//				break;
//			case 11:		
//				rec.type = niutype.huluj;	
//				break;
//			case 12:		
//				rec.type = niutype.huluq;	
//				break;
//			case 13:		
//				rec.type = niutype.huluk;		
//				break;
//			} 
//		}
//		else if(tonghua(mycards)&&code>0){
//			rec.rec = 0;
//			rec.type =niutype.tonghua;
//		}
//		else if(shunzi(mycards)&&code>0)
//		{
//
//			//			if(tonghuashun(mycards)){
//			//				rec.rec = 0;
//			//				rec.type =niutype.tonghuashun;
//			//			}else{
//			//				rec.rec = 0;
//			//				rec.type = niutype.shunzi;
//			//			}
//
//			rec.rec = 0;
//			rec.type = niutype.shunzi;
//
//		}else if(checkwuhuaniu(mycards)&&code>0)
//		{
//			rec.rec = 0;
//			rec.type = niutype.wuhuaniu;
//		}
//		else if(quandan(mycards)&&code>0)
//		{
//			rec.rec = 0;
//			rec.type2 =niutype.quandan;
//		}
		//else
		{
			Vector<Vector<card>> cardvecs = splitcards(mycards);
			if(cardvecs.size() == 0)
			{
				rec.rec = 0;
				rec.type = niutype.niu0;
			}
			else
			{
				rec.rec = 0;
				Vector<card> points = new Vector<card>();
				int niupoint = findmax(cardvecs, mycards, zucards, points);
				switch (niupoint) {
				case 0:		
					rec.type = niutype.niu0;
					break;
				case 1:		
					rec.type = niutype.niu1;		
					break;
				case 2:				
					rec.type = niutype.niu2;
					break;
				case 3:			
					rec.type = niutype.niu3;	
					break;
				case 4:			
					rec.type = niutype.niu4;	
					break;
				case 5:			
					rec.type = niutype.niu5;	
					break;
				case 6:			
					rec.type = niutype.niu6;	
					break;
				case 7:			
					rec.type = niutype.niu7;	
					break;
				case 8:			
					rec.type = niutype.niu8;	
					break;
				case 9:			
					rec.type = niutype.niu9;	
					break;
				case 10:		
					rec.type = niutype.niu10;	
					int allp = Allpoint(points);
					if(allp == 20)
					{
						rec.ran = 1;
					}
					else
					{
						rec.ran = 2;
					}
					break;
				default:
					rec.rec = 2;//异常!
					break;
				}
			}
		}
		return rec;
	}
	private static int Allpoint(Vector<card> mycards)
	{
		int point = 0;
		for(int i=0; i<mycards.size(); i++)
		{
			point += mycards.get(i).type.get_value()%10;
		}
		return point;
	}
	public static ranpairec checkran(Vector<card> mycards, int ischeckran)
	{
		ranpairec rec = new ranpairec();
		Vector<Vector<card>> cardvecs = splitcards(mycards);
		if(cardvecs.size() > 0 && ischeckran == 0)
		{
			//燃了
			Vector<card> points = new Vector<card>();
			rec.maxpoing = findmax(cardvecs, mycards, rec.zucards, points);
			int allpoint = Allpoint(points);
			if(allpoint == 10)
			{
				rec.ran = 1;
			}
			else if(allpoint == 20)
			{
				rec.ran = 1;
			}
		}
		else
		{
			rec.ran = 0;
			//没燃
			if(mycards.size() > 0)
			{
				rec.maxpoing = mycards.get(mycards.size()-1).type.get_value()%10;
			}
			else
			{
				rec.maxpoing = 0;
			}
		}
		return rec;
	}
	/**
	 * 
	 * 
	 * */
	public static niutyperec checkniutype(Vector<card> niu, Vector<card> point, Vector<card> mycards)
	{
		niutyperec rec = new niutyperec();
		Vector<card> allcards = new Vector<>();
		for(int i=0; i<niu.size(); i++)
		{
			allcards.addElement(niu.get(i));
		}
		for(int j=0; j<point.size(); j++)
		{
			allcards.addElement(point.get(j));
		}
		if(!isallhave(allcards, mycards))
		{
			rec.rec = 1;//牌不存在
		}
		int zhadan = zhadan(mycards, new Vector<card>());
		int hulu = hulu(mycards);
		if(zhadan>0)
		{
			rec.rec = 0;
			switch (zhadan) {
			case 1:		
				rec.type = niutype.zhadana;		
				break;
			case 2:				
				rec.type = niutype.zhadan2;
				break;
			case 3:			
				rec.type = niutype.zhadan3;	
				break;
			case 4:			
				rec.type = niutype.zhadan4;	
				break;
			case 5:			
				rec.type = niutype.zhadan5;	
				break;
			case 6:			
				rec.type = niutype.zhadan6;	
				break;
			case 7:			
				rec.type = niutype.zhadan7;	
				break;
			case 8:			
				rec.type = niutype.zhadan8;	
				break;
			case 9:			
				rec.type = niutype.zhadan9;	
				break;
			case 10:		
				rec.type = niutype.zhadan10;		
				break;
			case 11:		
				rec.type = niutype.zhadanj;		
				break;
			case 12:		
				rec.type = niutype.zhadanq;		
				break;
			case 13:		
				rec.type = niutype.zhadank;		
				break;
			}
		}
		else if(checkwuhuaniu(mycards))
		{
			rec.rec = 0;
			rec.type = niutype.wuhuaniu;
		}
		else if(checkwuxiaoniu(mycards))
		{
			rec.rec = 0;
			rec.type = niutype.wuxiaoniu;
		}
		else if(hulu>0)
		{
			rec.rec = 0;switch (hulu) {
			case 1:		
				rec.type = niutype.hulua;		
				break;
			case 2:				
				rec.type = niutype.hulu2;
				break;
			case 3:			
				rec.type = niutype.hulu3;
				break;
			case 4:			
				rec.type = niutype.hulu4;
				break;
			case 5:			
				rec.type = niutype.hulu5;
				break;
			case 6:			
				rec.type = niutype.hulu6;
				break;
			case 7:			
				rec.type = niutype.hulu7;
				break;
			case 8:			
				rec.type = niutype.hulu8;
				break;
			case 9:			
				rec.type = niutype.hulu9;	
				break;
			case 10:		
				rec.type = niutype.hulu10;		
				break;
			case 11:		
				rec.type = niutype.huluj;	
				break;
			case 12:		
				rec.type = niutype.huluq;	
				break;
			case 13:		
				rec.type = niutype.huluk;		
				break;
			}
		}
		else if(shunzi(mycards))
		{
			rec.rec = 0;
			rec.type = niutype.shunzi;
		}
		else
		{
			rec.rec = 0;
			int niupoint = checkniu(niu, point);
			switch (niupoint) {
			case 0:		
				rec.type = niutype.niu0;
				break;
			case 1:		
				rec.type = niutype.niu1;		
				break;
			case 2:				
				rec.type = niutype.niu2;
				break;
			case 3:			
				rec.type = niutype.niu3;	
				break;
			case 4:			
				rec.type = niutype.niu4;	
				break;
			case 5:			
				rec.type = niutype.niu5;	
				break;
			case 6:			
				rec.type = niutype.niu6;	
				break;
			case 7:			
				rec.type = niutype.niu7;	
				break;
			case 8:			
				rec.type = niutype.niu8;	
				break;
			case 9:			
				rec.type = niutype.niu9;	
				break;
			case 10:		
				rec.type = niutype.niu10;		
				break;
			default:
				rec.rec = 2;//异常!
				break;
			}
		}

		return rec;
	}
}
